﻿var map;
//底图
var basemap;
//注记
var annolayer;
//克里金插值要素
var kriginggraphic;

//站点要素
var sitesGraphic;

//所有站点代码
var allStations;

//异常数据
var abnormalData = [];
//高亮显示图层
var highlightGraphics;

//控制面板数据
var kzmbData = [];

//标注图层
var biaozhuGraphics;

//当前页
var currentIndex = 1;

var toolbar = null; //工具

 var   period= 27; //色段数目
  var  segmentedColorObj=null;//色标分段

require(["esri/map",
		"esri/toolbars/navigation",
		"esri/symbols/Font",
		"esri/geometry/Polygon",
		"esri/layers/LabelLayer",
		"dojo/dom",
		"esri/dijit/Measurement",
		"dojo/on",
		"dojo/parser",
		"esri/dijit/Scalebar",
		"esri/layers/FeatureLayer",
		"esri/layers/GraphicsLayer",
		"esri/geometry/Point",
		"esri/geometry/Polyline",
		"esri/geometry/Circle",
		"esri/symbols/Symbol",
		"esri/symbols/SimpleMarkerSymbol",
		"esri/symbols/SimpleFillSymbol",
		"esri/symbols/SimpleLineSymbol",
		"esri/symbols/TextSymbol",
		"dijit/layout/ContentPane",
		"dijit/TitlePane",
		"dojo/_base/Color",
		"dijit/registry",
		"dijit/Toolbar",
		"dojo/domReady!"
	],
	function(Map,
		navigation,
		Font,
		Polygon,
		LabelLayer,
		dom,
		Measurement,
		on,
		parser,
		Scalebar,
		FeatureLayer,
		GraphicsLayer,
		Point,
		Polyline,
		Circle,
		Symbol,
		SimpleMarkerSymbol,
		SimpleFillSymbol,
		SimpleLineSymbol,
		TextSymbol,
		ContentPane,
		TitlePane,
		Color,
		registry,
		Toolbar,
		domReady) {
		map = new Map("map", {
			logo: false,
			center: [105.5, 30.6],
			slider: false,
			zoom: 9
			//			slider: true,
			//			sliderStyle: "large",
			//			sliderPosition: "bottom-left",
			//			sliderLabels: ["", "国", "", "", "省", "", "", "市", "", "", "县"]
		});

		defineClassesBeforInitMap();
		var layer = new TDTRoadLayer();
		var annolayer = new TDTAnnoLayer();
		var imglayer = new TDTImageLayer();
		var imgannolayer = new TDTImgAnnoLayer();
		map.addLayer(layer);
		map.addLayer(annolayer);

		parser.parse();

		kriginggraphic = new esri.layers.GraphicsLayer();
		map.addLayer(kriginggraphic);

		//添加站点图层
		sitesGraphic = new esri.layers.GraphicsLayer();
		map.addLayer(sitesGraphic);

		//添加高亮显示图层
		highlightGraphics = new esri.layers.GraphicsLayer();
		map.addLayer(highlightGraphics);

		//标注图层
		biaozhuGraphics = new esri.layers.GraphicsLayer();
		map.addLayer(biaozhuGraphics);

		//当地图移出到地图范围外时回到遂宁
		map.on("pan-end", panoutmap);

		function panoutmap(evt) {
			var extent = evt.extent;
			if(extent.xmax > 220 || extent.xmin < -180 || extent.ymax > 90 || extent.ymin < -90) {
				var lelve = map.getZoom();
				var pt = new Point(102.847, 35.0473);
				map.centerAndZoom(pt, lelve);
			}

		};
//		$('#segmentedColorContainer').hide();
		  //显示隐藏图例
$('#legendbar').on('click', function() {
    if (!$(this).hasClass('active')) {
      $(this).addClass('active');
      $('#segmentedColorContainer').show();
    } else {
      $(this).removeClass('active');
      $('#segmentedColorContainer').hide();
    }
});

  /*隐藏和显示控制面板*/
  $('.openTrol').click(function() {
    $('#kzmb').hide();
    $('.conceal').show();
  });
  $('.conceal').click(function() {
    $('.conceal').hide();
    $('#kzmb').show();
  });
		init();

		//初始化位置
		zoomtoSuining();
//		document.getElementById("tuli").style.visibility = "hidden";
		//实时监测报警
		addThresholdAlarm();
		//色斑图
		//temperaturePlot(0.3);
		initGraphics();

		//初始化当前时间
		$("#showTime").text(getNowFormatDate1());

	});

//移动到遂宁范围内
function zoomtoSuining() {
	require(["esri/geometry/Point", "esri/geometry/Extent"],
		function(Point, Extent) {
			if(map.height > 600 && map.height < 850) {
				var pt = new Point(105.7, 30.5);
				map.centerAndZoom(pt, 11);
			} else {
				var extent = new Extent(104, 29, 106, 32, map.spatialReference);
				map.setExtent(extent);
			}
		});
}



function initGraphics() {
	//鼠标移动到时显示
	sitesGraphic.on("mouse-over", function(event) {
		//showinfowindow((event.x), (event.y), event.graphic);
		//map.infoWindow.resize(230, 170);
		map.infoWindow.setTitle("站点详细信息");
		map.infoWindow.setContent("站点:" + event.graphic.attributes.id + "    站名：" + event.graphic.attributes.Name + "<br></br>" + "风速:" + event.graphic.attributes.WindSpeed + "m/s    风向：" + event.graphic.attributes.WindDirection + "°" + "<br></br>" + "降水:" + event.graphic.attributes.rain + "mm    温度：" + event.graphic.attributes.tem + "℃" + "<br></br>" + "气压:" + event.graphic.attributes.pressure + "pa" + "    湿度：" + event.graphic.attributes.humidity + "%");
		map.infoWindow.show(event.graphic.geometry);
	});
	//鼠标离开时
	sitesGraphic.on("mouse-out", function(event) {
		//closeInfoWin(event);
		map.infoWindow.hide();
	});
	//鼠标点击时
	sitesGraphic.on("click", function(event) {
		var stationId = event.graphic.attributes.id;
		var currentime = getNowFormatDate();
		var stationName = event.graphic.attributes.Name;

		layer.open({
			type: 2,
			title: "站点历史数据查询",
			skin: 'layui-layer-rim', //加上边框
			area: ['830px', '560px'], //宽高
			content: 'SitesDetail.html?' + stationId + "&&" + currentime + "&&" + stationName
		});
	});

	//鼠标移动到时显示
	highlightGraphics.on("mouse-over", function(event) {
		//showinfowindow((event.x), (event.y), event.graphic);
		//map.infoWindow.resize(230, 170);
		map.infoWindow.setTitle("站点详细信息");
		map.infoWindow.setContent("站点:" + event.graphic.attributes.id + "    站名：" + event.graphic.attributes.Name + "<br></br>" + "风速:" + event.graphic.attributes.WindSpeed + "m/s    风向：" + event.graphic.attributes.WindDirection + "°" + "<br></br>" + "降水:" + event.graphic.attributes.rain + "mm    温度：" + event.graphic.attributes.tem + "℃" + "<br></br>" + "气压:" + event.graphic.attributes.pressure + "pa" + "    湿度：" + event.graphic.attributes.humidity + "%");
		map.infoWindow.show(event.graphic.geometry);
	});
	//鼠标离开时
	highlightGraphics.on("mouse-out", function(event) {
		//closeInfoWin(event);
		map.infoWindow.hide();
	});
	//鼠标点击时
	highlightGraphics.on("click", function(event) {
		var stationId = event.graphic.attributes.id;
		var currentime = getNowFormatDate();
		var stationName = event.graphic.attributes.Name;

		layer.open({
			type: 2,
			title: "站点历史数据查询",
			skin: 'layui-layer-rim', //加上边框
			area: ['830px', '560px'], //宽高
			content: 'SitesDetail.html?' + stationId + "&&" + currentime + "&&" + stationName
		});
	});
}

//添加报警点
function addThresholdAlarm() {
	require(["esri/geometry/Point"],
		function(Point) {

			var selectobject2 = document.getElementById("szbz");

			if(!selectobject2.checked) {
				biaozhuGraphics.clear();
				sitesGraphic.clear();
				highlightGraphics.clear();
				return;
			}
			//加载层
init();
			var index = layer.load(2, {
				shade: false
			}); //0代表加载的风格，支持0-2
			sitesGraphic.clear();
			highlightGraphics.clear();
//			document.getElementById("tuli").style.visibility = "hidden";
			$.ajax({
				url: "http://61.157.118.158:8088/sndm/api/StationManageAction/getStationInfoList",
				dataType: 'json',
				data: '',
				jsonp: 'callback', //传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(默认为:callback)  

				success: function(result) {
					var stationInformation = result;
					var stations = "";
					for(var k = 0; k < stationInformation.total; k++) {
						if(k < stationInformation.total - 1) {
							stations += stationInformation.rows[k].iiiii + ",";
						} else {
							stations += stationInformation.rows[k].iiiii;
						}
					}
					var utctime = getNowFormatDateWithOut();
					var url = "http://61.157.118.158:8088/sndm/api/surfChnMulHor/getSurfEleByTimeAndStaID?dataCode=SURF_CHN_MUL_HOR&elements=Station_Name,City,Datetime,Station_Id_C,Station_levl,PRS,TEM,RHU,PRE_1h,WIN_D_INST,WIN_S_INST&times=" + utctime + "&staIds=" + stations;
					$.ajax({
						type: 'post',
						url: url,
						data: $("#myform").serialize(),
						cache: false,
						dataType: 'json',
						success: function(data) {
							for(var k = 0; k < stationInformation.total; k++) {
								var imgurl = "../img/nornal.png";
								var symbol = new esri.symbol.PictureMarkerSymbol(imgurl, 24, 24);
								var pt = new Point(parseFloat(stationInformation.rows[k].loN), parseFloat(stationInformation.rows[k].laN));
								var graphic = new esri.Graphic(pt, symbol);
								graphic.setAttributes({
									"Name": stationInformation.rows[k].sname,
									"createTime": stationInformation.rows[k].createTime,
									"id": stationInformation.rows[k].iiiii,
									"City": stationInformation.rows[k].muncpl,
									"Cnty": stationInformation.rows[k].sname,
									"WindSpeed": "undefined",
									"WindDirection": "undefined",
									"tem": "undefined",
									"rain": "undefined",
									"pressure": "undefined",
									"humidity": "undefined"
								});

								sitesGraphic.add(graphic);
							}

							var alarmInformation = data;
							for(var i = 0; i < alarmInformation.rowCount; i++) {
								for(var k = 0; k < sitesGraphic.graphics.length; k++) {
									var currentGraphic = sitesGraphic.graphics[k];
									if(currentGraphic.attributes.id == alarmInformation.DS[i].Station_Id_C) {
										if((alarmInformation.DS[i].WIN_S_INST > 10 && alarmInformation.DS[i].WIN_S_INST != "999999") || (alarmInformation.DS[i].TEM > 9 && alarmInformation.DS[i].TEM != "999999") || (alarmInformation.DS[i].RHU > 100 && alarmInformation.DS[i].RHU != "999999") || (alarmInformation.DS[i].PRE > 992 && alarmInformation.DS[i].PRE != "999999") || (alarmInformation.DS[i].PRE_1h > 100 && alarmInformation.DS[i].PRE_1h != "999999")) {
											var alarmInformationType = "";
											var imgurl = "../img/alarm.png";
											var symbol = new esri.symbol.PictureMarkerSymbol(imgurl, 24, 24);
											currentGraphic.setSymbol(symbol);
											if(alarmInformation.DS[i].WIN_S_INST > 10) {
												alarmInformationType = "台风报警";
											}
											if(alarmInformation.DS[i].TEM > 39) {
												alarmInformationType = "高温报警";
											}
											if(alarmInformation.DS[i].RHU > 100) {
												alarmInformationType = "湿度报警";
											}
											if(alarmInformation.DS[i].PRS > 992) {
												alarmInformationType = "高压报警";
											}
											if(alarmInformation.DS[i].PRE_1h > 992) {
												alarmInformationType = "暴雨报警";
											}
											abnormalData.push({
												type: alarmInformationType,
												data: alarmInformation.DS[i],
												publishUnit: "遂宁市气象局", //发布单位
												publishMode: 0, //发布方式，0，为未选择，1为短信，2为系统语音，3为两者
												publushArea: "area全区", //发布范围，0为全区，1为。
												content: "降水为100毫米、超过阈值，为20年一遇！"
											});
										}
										if(alarmInformation.DS[i].TEM == "999999") {
											currentGraphic.attributes.tem = 0;
										} else {
											currentGraphic.attributes.tem = alarmInformation.DS[i].TEM;
										}
										if(alarmInformation.DS[i].WIN_S_INST == "999999") {
											currentGraphic.attributes.WindSpeed = 0;
										} else {
											currentGraphic.attributes.WindSpeed = alarmInformation.DS[i].WIN_S_INST;
										}
										if(alarmInformation.DS[i].WIN_D_INST == "999999") {
											currentGraphic.attributes.WindDirection = 0;
										} else {
											currentGraphic.attributes.WindDirection = alarmInformation.DS[i].WIN_D_INST;
										}
										if(alarmInformation.DS[i].PRE_1h == "999999") {
											currentGraphic.attributes.rain = 0;
										} else {
											currentGraphic.attributes.rain = alarmInformation.DS[i].PRE_1h;
										}
										if(alarmInformation.DS[i].PRS == "999999") {
											currentGraphic.attributes.pressure = 0;
										} else {
											currentGraphic.attributes.pressure = alarmInformation.DS[i].PRS;
										}
										if(alarmInformation.DS[i].RHU == "999999") {
											currentGraphic.attributes.humidity = 0;
										} else {
											currentGraphic.attributes.humidity = alarmInformation.DS[i].RHU;
										}

									}
								}
							}
							layer.close(index);

							if(abnormalData.length != 0) {
								showAlarmInformation();
								//右下角报警信息
								$("#messageHeaderContent").text(abnormalData[0].type);
								$("#datatimes").text(abnormalData[0].data.Datetime);
								$("#stationId").text(abnormalData[0].data.Station_Id_C);
								$("#stationName").text(abnormalData[0].data.Station_Name);
								$("#alarmContent").text(abnormalData[0].content);

								//编辑发布信息publishContent
								$("#publishUnit").attr("value", abnormalData[0].publishUnit);
								$("#publushArea").attr("value", "area全区");
								$("#datatime").text(abnormalData[0].data.Datetime);
								$("#contents").text(abnormalData[0].content);
//								$('#stationId1').selectpicker('val', abnormalData[0].data.Station_Id_C);
//								$('#stationName1').selectpicker('val', abnormalData[0].data.Station_Id_C);
							}
						}

					});

				},
				error: function() {
					alert("请求失败");
					//错误处理  
				}
			});
		}
	);
}

//生成等值线图
function temperatureContourMap(alpha) {
	require(["esri/geometry/Point", "esri/SpatialReference",
			"esri/symbols/SimpleMarkerSymbol", "esri/graphic", "esri/geometry/Polygon", "esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol", "esri/Color",'Utils/SegmentedColor',
  'dojo/on'
		],
		function(Point, SpatialReference, SimpleMarkerSymbol, Graphic, Polygon, SimpleFillSymbol, SimpleLineSymbol, Color,SegmentedColor,on) {
			var selectobject3 = document.getElementById("sb");
			if(!selectobject3.checked) {
				kriginggraphic.clear();
				return;
			}
			if(kriginggraphic) {
				kriginggraphic.clear();
			}
//			document.getElementById("tuli").style.visibility = "visible";

			var selectobject = document.getElementById("water");
			var selectobject1 = document.getElementById("temElement");
//			var thValue = document.getElementById("tuliLabel");
//			if(selectobject.checked) {
//				thValue.innerHTML = "降雨";
//			} else {
//				thValue.innerHTML = "气温（℃）";
//			}

			var longitude = [];
			var latitude = [];
			var response = [];
			var csv = getTemperatureData();
			//获取并展示数据

			for(var i = 0; i < csv.DS.length; i++) {
				longitude.push(parseFloat(csv.DS[i].Lon) * Math.PI / 180 * 6378137.0);
				latitude.push(6378137.0 / 2 * Math.log((1.0 + Math.sin(parseFloat(csv.DS[i].Lat) * Math.PI / 180)) / (1.0 - Math.sin(parseFloat(csv.DS[i].Lat) * Math.PI / 180))));

				if(selectobject1.checked) {
					if(parseFloat(csv.DS[i].TEM) == 999999) {
						response.push(0);
					} else {

						response.push(parseFloat(csv.DS[i].TEM));
					}

				} else if(selectobject.checked) {
					if(parseFloat(csv.DS[i].PRS) == 999999) {
						response.push(0);
					} else {

						response.push(parseFloat(csv.DS[i].PRS));
					}
				}

			}
			var x = response.concat(longitude).concat(latitude).toString();
			x = x.split(',');
			var dataCSV = [];
			var krigingValue = [];
			//window.alert(x);
			for(var i = 0; i < x.length; i++) {
				x[i] = parseFloat(x[i]);
				dataCSV[dataCSV.length] = x[i]
			}

			//make that array into three parts.
			var pm = dataCSV.slice(0, dataCSV.length / 3)
			var csvX = dataCSV.slice(dataCSV.length / 3, dataCSV.length / 3 * 2);
			var csvY = dataCSV.slice(dataCSV.length / 3 * 2, dataCSV.length);

			//set max, min functions for Array
			Array.prototype.max = function() {
				return Math.max.apply(null, this);
			};

			Array.prototype.min = function() {
				return Math.min.apply(null, this);
			};
			var rangemaxX = 11855525.769483434;
			var rangeminX = 11632886.787896892;
			var rangemaxY = 3723995.0672950186;
			var rangeminY = 3452236.5008381056;
			var rangemaxPM = pm.max();
			var rangeminPM = pm.min();
			var colorperiod = (rangemaxPM - rangeminPM) / 5

			// get the range values
			var xl = rangemaxX - rangeminX;
			var yl = rangemaxY - rangeminY;
			var gridX = xl / 100
			var gridY = yl / 100
			var gridPoint = [];
			var llmin = esri.geometry.xyToLngLat(rangeminX, rangeminY);
			var llmax = esri.geometry.xyToLngLat(rangemaxX, rangemaxY);
			var lggridx = (llmax[0] - llmin[0]) / 100
			var lggridy = (llmax[1] - llmin[1]) / 100

			//Based on the position of polygon, get the kriging value.

			var variogram;
			setValue();
			grid();

			function setValue() {
				var t = pm;
				var x = csvX;
				var y = csvY;
				var model = "exponential";
				var sigma2 = 0,
					alpha = 100;
				variogram = kriging.train(t, x, y, model, sigma2, alpha);
			}

			function getKring(xk, yk) {
				//window.alert(variogram);
				var xnew, ynew /* Pair of new coordinates to predict */ ;
				var tpredicted = kriging.predict(xk, yk, variogram);
				return tpredicted;
			}

			// create grids and set kriging values for them.
			function grid() {
				//create the range of Kriging based on given points
				var gX = rangeminX;
				for(var i = 0; i < 100; i++) {
					gX = gX + gridX;
					var gY = rangeminY
					for(var j = 0; j < 100; j++) {
						gY = gY + gridY;

						var pp = esri.geometry.xyToLngLat(gX, gY);
						krigingValue[krigingValue.length] = getKring(gX, gY)
						gridPoint[gridPoint.length] = esri.geometry.xyToLngLat(gX, gY);
					}
				}

			}

			createKriging();

			function ShowLocation(x, y) {
				var point = new Point(x, y, new SpatialReference({
					wkid: 4326
				}));
				var simpleMarkerSymbol = new SimpleMarkerSymbol('blue');
				var graphic = new Graphic(point, simpleMarkerSymbol);
				kriginggraphic.add(graphic);

			};

			function createKriging() {
				var suiningwkt = "POLYGON((105.61447 30.97882,105.66577 30.92742,105.72907 30.90762,105.73077 30.86712,105.79307 30.80192,105.77657 30.78382,105.79017 30.71172,105.83467 30.58662,105.87287 30.56022,105.85687 30.51582,105.88107 30.47582,105.92017 30.47012,105.93007 30.52082,105.96747 30.48052,105.95727 30.43052,105.98397 30.41632,105.99727 30.37912,105.93987 30.37482,105.84257 30.41392,105.81657 30.44022,105.76827 30.40672,105.74987 30.36452,105.70547 30.30262,105.72027 30.25742,105.66987 30.25552,105.61927 30.27662,105.61677 30.23702,105.63897 30.18922,105.57657 30.17632,105.55617 30.18552,105.51717 30.20492,105.46967 30.25112,105.42097 30.26322,105.40347 30.29282,105.36717 30.27882,105.35387 30.31092,105.25517 30.28272,105.11687 30.34872,105.08777 30.40352,105.08777 30.46412,105.05697 30.52342,105.06437 30.53802,105.08267 30.55322,105.16497 30.67822,105.16637 30.70842,105.26847 30.75442,105.25707 30.82782,105.22627 30.87832,105.19297 30.89372,105.19337 30.98232,105.17147 31.03682,105.22637 31.10572,105.28477 31.10342,105.37887 31.15462,105.38597 31.11422,105.41317 31.07392,105.50707 31.02952,105.53287 31.02842,105.59147 30.97592,105.61447 30.97882))";
				var feature = (new ol.format.WKT()).readFeature(suiningwkt);
				var json = (new ol.format.GeoJSON()).writeFeature(feature);
				//pointsWithinPolygon
				//isolines
				//booleanContains
				var points = [];
				for(var i = 0; i < 100; i++) {
					for(var j = 0; j < 100; j++) {
						points.push([llmin[0] + i * lggridx, llmin[1] + j * lggridy]);
					}
				}
				var pointscollection = turf.points(points);
				var polygon = turf.polygon(JSON.parse(json).geometry.coordinates);

				var ptsWithin = turf.pointsWithinPolygon(pointscollection, polygon);
				var mydate = new Date()
				console.log("开始插值" + mydate.getSeconds() + ":" + mydate.getMilliseconds().toString());
				for(var i = 0; i < pointscollection.features.length; i++) {
					var converted = pointscollection.features[i].geometry.coordinates;
					var webpoint = esri.geometry.lngLatToXY(converted[0], converted[1]);
					pointscollection.features[i].properties.temperature = getKring(webpoint[0], webpoint[1]);
				}
				var newmydate = new Date()
				console.log("结束插值" + newmydate.getSeconds() + ":" + newmydate.getMilliseconds().toString());
				console.log(pointscollection)
				var breaks = [0];
				for(var i = 0; i < 5; i++) {
					breaks.push(rangemaxPM - (4 - i) * colorperiod);
				}

				var lines = turf.isolines(pointscollection, breaks, {
					zProperty: 'temperature'
				});
				
				      //引入色标分段
      segmentedColorObj = new SegmentedColor(0, 50, this.period);
      segmentedColorObj.createSegmentedColor();
      segmentedColorObj.createSegmentedColorValue();
      
            var colorArr = segmentedColorObj.getGradientColorArr();
      var colorValueArr = segmentedColorObj.getGradientColorValueArr();

				var temcolors = [
					[0, 0, 255, alpha],
					[0, 20, 255, alpha],
					[0, 69, 255, alpha],
					[0, 101, 255, alpha],
					[0, 133, 255, alpha],
					[0, 255, 148, alpha],
					[0, 255, 115, alpha],
					[0, 255, 82, alpha],
					[0, 255, 41, alpha],
					[0, 255, 8, alpha],
					[16, 255, 0, alpha],
					[49, 255, 0, alpha],
					[82, 255, 0, alpha],
					[115, 255, 0, alpha],
					[148, 255, 0, alpha],
					[181, 255, 0, alpha],
					[222, 255, 0, alpha],
					[255, 255, 0, alpha],
					[255, 231, 0, alpha],
					[255, 195, 0, alpha],
					[255, 162, 0, alpha],
					[255, 130, 0, alpha],
					[255, 97, 0, alpha],
					[255, 65, 0, alpha],
					[255, 44, 0, alpha],
					[255, 32, 0, alpha],
					[255, 20, 0, alpha],
					[255, 0, 0, alpha]
				];
				var waterColors = [
					[255, 0, 0, alpha],
					[255, 20, 0, alpha],
					[255, 32, 0, alpha],
					[255, 44, 0, alpha],
					[0, 0, 255, alpha],
					[0, 20, 255, alpha],
					[0, 69, 255, alpha],
					[0, 101, 255, alpha],
					[0, 133, 255, alpha],
					[0, 255, 148, alpha],
					[0, 255, 115, alpha],
					[0, 255, 82, alpha],
					[0, 255, 41, alpha],
					[0, 255, 8, alpha],
					[16, 255, 0, alpha],
					[49, 255, 0, alpha],
					[82, 255, 0, alpha],
					[115, 255, 0, alpha],
					[148, 255, 0, alpha],
					[181, 255, 0, alpha],
					[222, 255, 0, alpha],
					[255, 255, 0, alpha],
					[255, 231, 0, alpha],
					[255, 195, 0, alpha],
					[255, 162, 0, alpha],
					[255, 130, 0, alpha],
					[255, 97, 0, alpha],
					[255, 65, 0, alpha]
				];
				var selectobject = document.getElementById("water");
				var selectobject1 = document.getElementById("temElement");
				var colors;
//				if(selectobject.checked) {
//					colors = waterColors;
//
//				} else {
//
//					colors = temcolors;
//				}
colors=colorArr;
				//return;lines.features.length
				for(var i = 0; i < lines.features.length; i++) {
					for(var j = 0; j < lines.features[i].geometry.coordinates.length; j++) {
						var polyline = new esri.geometry.Polyline(lines.features[i].geometry.coordinates[j]);
						var simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASH, new esri.Color([255, 0, 0]), 3);

						var polygon = new esri.geometry.Polygon(lines.features[i].geometry.coordinates[j]);
						var simpleFillSymbol = new SimpleFillSymbol();
						simpleFillSymbol.setOutline(new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_NULL, new esri.Color([255, 0, 0]), 2));
						if(lines.features[i].properties.temperature < -26) {
							simpleFillSymbol.setColor(new esri.Color(colors[0]));
						} else if(lines.features[i].properties.temperature < -24 && lines.features[i].properties.temperature >= -26) {
							simpleFillSymbol.setColor(new esri.Color(colors[1]));
						} else if(lines.features[i].properties.temperature < -22 && lines.features[i].properties.temperature >= -24) {
							simpleFillSymbol.setColor(new esri.Color(colors[2]));
						} else if(lines.features[i].properties.temperature < -20 && lines.features[i].properties.temperature >= -22) {
							simpleFillSymbol.setColor(new esri.Color(colors[3]));
						} else if(lines.features[i].properties.temperature < -18 && lines.features[i].properties.temperature >= -20) {
							simpleFillSymbol.setColor(new esri.Color(colors[4]));
						} else if(lines.features[i].properties.temperature < -16 && lines.features[i].properties.temperature >= -18) {
							simpleFillSymbol.setColor(new esri.Color(colors[5]));
						} else if(lines.features[i].properties.temperature < -14 && lines.features[i].properties.temperature >= -16) {
							simpleFillSymbol.setColor(new esri.Color(colors[6]));
						} else if(lines.features[i].properties.temperature < -12 && lines.features[i].properties.temperature >= -14) {
							simpleFillSymbol.setColor(new esri.Color(colors[7]));
						} else if(lines.features[i].properties.temperature < -10 && lines.features[i].properties.temperature >= -12) {
							simpleFillSymbol.setColor(new esri.Color(colors[8]));
						} else if(lines.features[i].properties.temperature < -8 && lines.features[i].properties.temperature >= -10) {
							simpleFillSymbol.setColor(new esri.Color(colors[9]));
						} else if(lines.features[i].properties.temperature < -6 && lines.features[i].properties.temperature >= -8) {
							simpleFillSymbol.setColor(new esri.Color(colors[10]));
						} else if(lines.features[i].properties.temperature < -4 && lines.features[i].properties.temperature >= -6) {
							simpleFillSymbol.setColor(new esri.Color(colors[11]));
						} else if(lines.features[i].properties.temperature < -2 && lines.features[i].properties.temperature >= -4) {
							simpleFillSymbol.setColor(new esri.Color(colors[12]));
						} else if(lines.features[i].properties.temperature < 0 && lines.features[i].properties.temperature >= -2) {
							simpleFillSymbol.setColor(new esri.Color(colors[13]));
						} else if(lines.features[i].properties.temperature < 2 && lines.features[i].properties.temperature >= 0) {
							simpleFillSymbol.setColor(new esri.Color(colors[14]));
						} else if(lines.features[i].properties.temperature < 4 && lines.features[i].properties.temperature >= 2) {
							simpleFillSymbol.setColor(new esri.Color(colors[15]));
						} else if(lines.features[i].properties.temperature < 6 && lines.features[i].properties.temperature >= 4) {
							simpleFillSymbol.setColor(new esri.Color(colors[16]));
						} else if(lines.features[i].properties.temperature < 8 && lines.features[i].properties.temperature >= 6) {
							simpleFillSymbol.setColor(new esri.Color(colors[17]));
						} else if(lines.features[i].properties.temperature < 10 && lines.features[i].properties.temperature >= 8) {
							simpleFillSymbol.setColor(new esri.Color(colors[18]));
						} else if(lines.features[i].properties.temperature < 12 && lines.features[i].properties.temperature >= 10) {
							simpleFillSymbol.setColor(new esri.Color(colors[19]));
						} else if(lines.features[i].properties.temperature < 14 && lines.features[i].properties.temperature >= 12) {
							simpleFillSymbol.setColor(new esri.Color(colors[20]));
						} else if(lines.features[i].properties.temperature < 18 && lines.features[i].properties.temperature >= 15) {
							simpleFillSymbol.setColor(new esri.Color(colors[21]));
						} else if(lines.features[i].properties.temperature < 21 && lines.features[i].properties.temperature >= 18) {
							simpleFillSymbol.setColor(new esri.Color(colors[22]));
						} else if(lines.features[i].properties.temperature < 25 && lines.features[i].properties.temperature >= 21) {
							simpleFillSymbol.setColor(new esri.Color(colors[23]));
						} else if(lines.features[i].properties.temperature < 28 && lines.features[i].properties.temperature >= 25) {
							simpleFillSymbol.setColor(new esri.Color(colors[24]));
						} else if(lines.features[i].properties.temperature < 31 && lines.features[i].properties.temperature >= 28) {
							simpleFillSymbol.setColor(new esri.Color(colors[25]));
						} else if(lines.features[i].properties.temperature < 34 && lines.features[i].properties.temperature >= 31) {
							simpleFillSymbol.setColor(new esri.Color(colors[26]));
						} else if(lines.features[i].properties.temperature >= 34) {
							simpleFillSymbol.setColor(new esri.Color(colors[27]));
						};

						var graphic = new Graphic(polygon, simpleFillSymbol);
						kriginggraphic.add(graphic);

					}
				}
			}

		})
}

//获取当前时间
function getNowFormatDate() {
	var date = new Date();
	var seperator1 = "-";
	var seperator2 = ":";
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if(month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if(strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
		date.getHours() + seperator2 + date.getMinutes() +
		seperator2 + date.getSeconds();
	return currentdate;
}
//获取当前时间
function getNowFormatDate1() {
	var date = new Date();
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if(month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if(strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = date.getFullYear() + "年" + month + "月" + strDate + "日" +
		date.getHours() + "时";
	return currentdate;
}

//字符时间转标准时间
function convertDataTime(theDateTime) {
	theDateTime = insert_flg(theDateTime, "-", 4);
	theDateTime = insert_flg(theDateTime, "-", 7);
	theDateTime = insert_flg(theDateTime, " ", 10);
	theDateTime = insert_flg(theDateTime, ":", 13);
	theDateTime = insert_flg(theDateTime, ":", 16);
	theDateTime = new Date(Date.parse(new Date(theDateTime)) - 8 * 60 * 60 * 1000);

	var month = theDateTime.getMonth() + 1;
	var strDate = theDateTime.getDate();
	if(month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if(strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}

	var hours = theDateTime.getHours();
	if(hours >= 0 && hours <= 9) {
		hours = "0" + hours;
	}
	var currentdate = theDateTime.getFullYear() + month + strDate +
		hours + "0000";
	return currentdate;
}

function insert_flg(str, flg, sn) {
	var newstr = "";
	var tmp = str.substring(0, sn);
	var next = str.substring(sn, str.length - 1);
	newstr += tmp + flg;
	newstr += next;
	return newstr;
}

//获取当前时间并转化为国际时
function getNowFormatDateWithOut() {
	var date = new Date();
	var UTCHour = date.getUTCHours();
	if(UTCHour >= 0 && UTCHour <= 9) {
		UTCHour = "0" + UTCHour;
	}
	var month = date.getUTCMonth() + 1;
	var strDate = date.getUTCDate();
	if(month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if(strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = date.getUTCFullYear() + month + strDate +
		UTCHour + "0000";
	return currentdate;
}

//确认发送
function confirmSending() {
	abnormalData.splice(0, 1);
	if(abnormalData.length != 0) {
		$("#messageHeaderContent").text(abnormalData[0].type);
		$("#datatimes").text(abnormalData[0].data.Datetime);
		$("#stationId").text(abnormalData[0].data.Station_Id_C);
		$("#stationName").text(abnormalData[0].data.Station_Name);
		$("#alarmContent").text(abnormalData[0].content);

		$("#publishUnit").attr("value", abnormalData[0].publishUnit);
		$("#publushArea").attr("value", "area全区");
		$("#stationName1").attr("value", abnormalData[0].data.Station_Name);
		$("#stationId1").attr("value", abnormalData[0].data.Station_Id_C);
		$("#datatime").text(abnormalData[0].data.Datetime);
		$("#contents").text(abnormalData[0].content);
	}

	if(abnormalData.length == 0) {
		document.getElementById("alarmMessage").style.visibility = "hidden";
	}
}

//编辑发布
function editPublish() {
	document.getElementById("publish").style.visibility = "visible";
}

//关闭编辑发布框
function closePublish() {
	document.getElementById("publish").style.visibility = "hidden";
}

//关闭右下角消息框
function closemessage() {
	abnormalData = [];
	document.getElementById("alarmMessage").style.visibility = "hidden";
}

//初始化
function init() {
	require(["esri/geometry/Point"],
		function(Point) {
				var index = layer.load(2, {
				shade: false
			}); //0代表加载的风格，支持0-2
			var selectobject = document.getElementById("water");
			var selectobject1 = document.getElementById("temElement");
			var selectobject11 = document.getElementById("windSpeedDirec");
			var selectobject12 = document.getElementById("conspicurity");
			var selectobject13 = document.getElementById("humidity");
			var selectobject14 = document.getElementById("pressure");
			var selectobject2 = document.getElementById("szbz");
			var selectobject3 = document.getElementById("sb");
			if(selectobject.checked || selectobject1.checked) {
				document.getElementById("sb").disabled = '';
			} else if(selectobject11.checked || selectobject12.checked || selectobject13.checked || selectobject14.checked) {
				document.getElementById("sb").disabled = 'disabled';
				selectobject3.checked=false;
			}

			if(selectobject3.checked) {
				temperatureContourMap(0.8);
			} else {
				kriginggraphic.clear();
			}

			if(selectobject2.checked) {
				$.ajax({
					url: "http://61.157.118.158:8088/sndm/api/StationManageAction/getStationInfoList",
					dataType: 'json',
					data: '',
					jsonp: 'callback', //传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(默认为:callback)  

					success: function(result) {
						var stationInformation = result;
						var stations = "";
						$("#diquSelect").empty();
						//					
						$("#publushArea").empty();
						//	

						$("#stationId1").empty();
						$("#stationName1").empty();

						for(var k = 0; k < stationInformation.total; k++) {
							if(k == 0) {
								$("#diquSelect").append("<option value='11'>遂宁市</option>");
								$("#publushArea").append("<option value='22'>全区</option>");
							}
							var selectoptions = "<option value='" + stationInformation.rows[k].iiiii +
								"'>" + stationInformation.rows[k].sname + "</option>";
							$("#diquSelect").append(selectoptions);
							$("#publushArea").append(selectoptions);
							var selectoptions1 = "<option value='" + stationInformation.rows[k].iiiii +
								"'>" + stationInformation.rows[k].iiiii + "</option>";
							$("#stationId1").append(selectoptions1);
							$("#stationName1").append(selectoptions);
							if(k < stationInformation.total - 1) {
								stations += stationInformation.rows[k].iiiii + ",";
							} else {
								stations += stationInformation.rows[k].iiiii;
							}
						}
						allStations = stations;
						var utctime = getNowFormatDateWithOut();
						var url = "http://61.157.118.158:8088/sndm/api/surfChnMulHor/getSurfEleByTimeAndStaID?dataCode=SURF_CHN_MUL_HOR&elements=Station_Name,City,Datetime,Station_Id_C,Station_levl,PRS,VIS,TEM,RHU,PRE_1h,WIN_D_INST,WIN_S_INST&times=" + utctime + "&staIds=" + stations;
						$.ajax({
							type: 'post',
							url: url,
							data: $("#myform").serialize(),
							cache: false,
							dataType: 'json',
							success: function(data) {
								if(data.colCount == "0") {
									alert("查询数据失败");
									return;
								}
								biaozhuGraphics.clear();
								var html = ""

								var thValue = document.getElementById("changeName");
								if(selectobject.checked) {
									thValue.innerHTML = selectobject.value;
								} else if(selectobject1.checked) {
									thValue.innerHTML = selectobject1.value;
								} else if(selectobject11.checked) {
									thValue.innerHTML = selectobject11.value;
								} else if(selectobject12.checked) {
									thValue.innerHTML = selectobject12.value;
								} else if(selectobject13.checked) {
									thValue.innerHTML = selectobject13.value;
								} else if(selectobject14.checked) {
									thValue.innerHTML = selectobject14.value;
								}

								for(var i = 0; i < data.DS.length; i++) {
									kzmbData.push(data.DS[i]);
								}
								for(var i = 0; i < 5; i++) {
									html += "<tr>";
									for(var j = 0; j < 3; j++) {
										//							html += "<td onclick='zoomTostation(""" + data.DS[i]["Station_Id_C"].toString() + """)'>";
										html += "<td class='station' station_id=" + kzmbData[i]["Station_Id_C"].toString() + ">";

										if(j == 0) {
											html += kzmbData[i]["Station_Id_C"].toString();
										} else if(j == 1) {
											html += kzmbData[i]["Station_Name"].toString();
										} else if(j == 2) {
											if(selectobject.checked) {
												html += kzmbData[i]["PRE_1h"].toString();
											} else if(selectobject1.checked) {
												html += kzmbData[i]["TEM"].toString();
											} else if(selectobject11.checked) {
												html += kzmbData[i]["WIN_S_INST"].toString() + "/" + kzmbData[i]["WIN_D_INST"].toString();
											} else if(selectobject12.checked) {
												html += kzmbData[i]["VIS"].toString();
											} else if(selectobject13.checked) {
												html += kzmbData[i]["RHU"].toString();
											} else if(selectobject14.checked) {
												html += kzmbData[i]["PRS"].toString();
											}

										}

										html += "</td>";
									}
									html += "</tr>"
								}
								document.getElementById('tableContent').innerHTML = html;
								$(".station").click(function() {
									zoomTostation($(this).attr("station_id"));

								});

								html = "";
								if(selectobject11.checked) {
									sitesGraphic.hide();
								} else {
									sitesGraphic.show();
								}
								var imgurl = "../img/wind.png";
								for(var i = 0; i < data.DS.length; i++) {
									var textSym;
									if(selectobject.checked) {
										textSym = new esri.symbol.TextSymbol(data.DS[i]["PRE_1h"].toString());
									} else if(selectobject1.checked) {
										textSym = new esri.symbol.TextSymbol(data.DS[i]["TEM"].toString());
									} else if(selectobject11.checked) {
										textSym = new esri.symbol.TextSymbol(data.DS[i]["WIN_S_INST"].toString());
										textSym1 = new esri.symbol.PictureMarkerSymbol(imgurl, 24, 24);
										textSym1.setAngle(parseFloat(data.DS[i]["WIN_S_INST"].toString()));
										var pt1 = new Point(parseFloat(stationInformation.rows[i].loN), parseFloat(stationInformation.rows[i].laN));
										var graphic1 = new esri.Graphic(pt1, textSym1);
										biaozhuGraphics.add(graphic1);

									} else if(selectobject12.checked) {
										textSym = new esri.symbol.TextSymbol(data.DS[i]["TEM"].toString());
									} else if(selectobject13.checked) {
										textSym = new esri.symbol.TextSymbol(data.DS[i]["RHU"].toString());
									} else if(selectobject14.checked) {
										textSym = new esri.symbol.TextSymbol(data.DS[i]["PRS"].toString());
									}
									textSym.yoffset=10;
									var pt = new Point(parseFloat(stationInformation.rows[i].loN), parseFloat(stationInformation.rows[i].laN));
									var graphic = new esri.Graphic(pt, textSym);
									biaozhuGraphics.add(graphic);

									html += "<tr>";

									for(var j = 0; j < 10; j++) {

										html += "<td>";
										if(j == 0) {
											html += data.DS[i]["Station_Id_C"].toString();
										} else if(j == 1) {
											html += data.DS[i]["Datetime"].toString();
										} else if(j == 2) {
											html += data.DS[i]["Station_Name"].toString();
										} else if(j == 3) {
											html += data.DS[i]["City"].toString();
										} else if(j == 4) {
											html += data.DS[i]["PRE_1h"].toString();
										} else if(j == 5) {
											html += data.DS[i]["TEM"].toString();
										} else if(j == 6) {
											html += data.DS[i]["RHU"].toString();
										} else if(j == 7) {
											html += data.DS[i]["PRS"].toString();
										} else if(j == 8) {
											html += data.DS[i]["WIN_D_INST"].toString();
										} else if(j == 9) {
											html += data.DS[i]["WIN_S_INST"].toString();
										}
										html += "</td>";
									}
									html += "</tr>"
								}
								document.getElementById('moretableContent').innerHTML = html;

							}
						});

					}
				});
			} else {
				sitesGraphic.clear();
				highlightGraphics.clear();
				biaozhuGraphics.clear();
			}
				layer.close(index);
		})
}

//显示隐藏更多信息
function showMoreInformation() {
	document.getElementById("moreInformation").style.visibility = "visible";
}

//关闭更多信息
function closeMoreInformation() {

	document.getElementById("moreInformation").style.visibility = "hidden";
}

//显示报警信息

function showAlarmInformation() {
	document.getElementById("alarmMessage").style.visibility = "visible";
}

//按条件查询更多信息
function searchMoreInformation() {

	var start = document.getElementById("start_time").value; //获取起始日期
	var end = document.getElementById("end_time").value; //获取结束日期
	start = start.replace(":", "");
	start = start.replace("-", "");
	start = start.replace("-", "");
	start = start.replace(" ", "");
	start = parseFloat(start.substr(0, start.length - 5));
	start = start.toString() + "0000";
	end = end.replace(":", "");
	end = end.replace("-", "");
	end = end.replace("-", "");
	end = end.replace(" ", "");
	end = parseFloat(end.substr(0, end.length - 5));
	end = end.toString() + "0000";
	start = convertDataTime(start);
	end = convertDataTime(end);
	var timaRange = "&timeRange=[" + start + "," + end + "]";

	var selectobject1 = document.getElementById("inlineCheckbox011");
	var selectobject2 = document.getElementById("inlineCheckbox012");
	var selectobject3 = document.getElementById("inlineCheckbox013");
	var diquselectvalue = $('#diquSelect option:selected').val();
	var utctime = getNowFormatDateWithOut();
	var stations;
	var lelves = "&staLevels=";
	if(diquselectvalue == "11") {
		stations = allStations;
	} else {
		stations = diquselectvalue;
	}
	var selectCount = 0;
	if(selectobject1.checked) {
		selectCount++;
		lelves += selectobject1.value + ",";
	}
	if(selectobject2.checked) {
		selectCount++;
		lelves += selectobject2.value + ",";
	}
	if(selectobject3.checked) {
		selectCount++;
		lelves += selectobject3.value + ",";
	}
	var url;
	//	if(selectCount > 0) {
	//		lelves = lelves.substring(0, lelves.length - 1);
	//		url = "http://61.157.118.158:8088/sndm/api/surfChnMulHor/getSurfEleByTimeRangeAndStaID?dataCode=SURF_CHN_MUL_HOR&elements=Station_Name,City,Datetime,Station_Id_C,Station_levl,PRS,TEM,RHU,PRE_1h,WIN_D_INST,WIN_S_INST"+timaRange + "&staIds=" + stations + lelves;
	//	} else {
	url = "http://61.157.118.158:8088/sndm/api/surfChnMulHor/getSurfEleByTimeRangeAndStaID?dataCode=SURF_CHN_MUL_HOR&elements=Station_Name,City,Datetime,Station_Id_C,Station_levl,PRS,TEM,RHU,PRE_1h,WIN_D_INST,WIN_S_INST" + timaRange + "&staIds=" + stations;
	//	}
	$.ajax({
		type: 'post',
		url: url,
		data: $("#myform").serialize(),
		cache: false,
		dataType: 'json',
		success: function(data) {
			if(data.colCount == "0") {
				html = "";
				document.getElementById('moretableContent').innerHTML = html;
				return;
			} else {
				html = ""
				for(var i = 0; i < data.DS.length; i++) {
					html += "<tr>";
					for(var j = 0; j < 10; j++) {

						html += "<td>";
						if(j == 0) {
							html += data.DS[i]["Station_Id_C"].toString();
						} else if(j == 1) {
							html += data.DS[i]["Datetime"].toString();
						} else if(j == 2) {
							html += data.DS[i]["Station_Name"].toString();
						} else if(j == 3) {
							html += data.DS[i]["City"].toString();
						} else if(j == 4) {
							html += data.DS[i]["PRE_1h"].toString();
						} else if(j == 5) {
							html += data.DS[i]["TEM"].toString();
						} else if(j == 6) {
							html += data.DS[i]["RHU"].toString();
						} else if(j == 7) {
							html += data.DS[i]["PRS"].toString();
						} else if(j == 8) {
							html += data.DS[i]["WIN_D_INST"].toString();
						} else if(j == 9) {
							html += data.DS[i]["WIN_S_INST"].toString();
						}
						html += "</td>";
					}
					html += "</tr>"
				}
				document.getElementById('moretableContent').innerHTML = html;
			}
		}
	});

}

//点击定位
function zoomTostation(id) {
	require(["esri/geometry/Point", "esri/geometry/Extent"],
		function(Point, Extent) {
			highlightGraphics.clear();
			if(sitesGraphic.graphics.length > 0) {
				for(var i = 0; i < sitesGraphic.graphics.length; i++) {
					if(sitesGraphic.graphics[i].attributes.id == id) {
						var imgurl = "../img/hightLight.png";
						var symbol = new esri.symbol.PictureMarkerSymbol(imgurl, 26, 26);
						var graphic = new esri.Graphic(sitesGraphic.graphics[i].geometry, symbol);
						graphic.setAttributes(sitesGraphic.graphics[i].attributes);
						highlightGraphics.add(graphic);
						if(highlightGraphics.graphics.length > 0) {
							highlightGraphics.graphics[0].symbol = symbol;
						}

						var pt = new Point(sitesGraphic.graphics[i].geometry.x, sitesGraphic.graphics[i].geometry.y);
						map.centerAndZoom(pt, 12);
						break;
					}
				}
			}
		});

}

function selectOnchang(obj) {
	//获取被选中的option标签选项 
	$('#stationId1').selectpicker('val', obj[obj.selectedIndex].value);
	$('#stationName1').selectpicker('val', obj[obj.selectedIndex].value);
}

//上一页
function pre() {
	if(currentIndex == 1) {
		alert("这是第一页");

	} else {
		var html = "";
		var selectobject = document.getElementById("water");
		var selectobject1 = document.getElementById("temElement");
		var thValue = document.getElementById("changeName");
		if(selectobject.checked) {
			thValue.innerHTML = selectobject.value;
		} else {
			thValue.innerHTML = selectobject1.value;
		}
		currentIndex--
		for(var i = 0; i < 5; i++) {
			html += "<tr>";
			for(var j = 0; j < 3; j++) {
				//							html += "<td onclick='zoomTostation(""" + data.DS[i]["Station_Id_C"].toString() + """)'>";
				html += "<td class='station' station_id=" + kzmbData[(currentIndex - 1) * 5 + i]["Station_Id_C"].toString() + ">";

				if(j == 0) {
					html += kzmbData[(currentIndex - 1) * 5 + i]["Station_Id_C"].toString();
				} else if(j == 1) {
					html += kzmbData[(currentIndex - 1) * 5 + i]["Station_Name"].toString();
				} else if(j == 2) {
					if(selectobject.checked) {
						html += kzmbData[(currentIndex - 1) * 5 + i]["PRE_1h"].toString();
					} else {
						html += kzmbData[(currentIndex - 1) * 5 + i]["TEM"].toString();
					}

				}

				html += "</td>";
			}
			html += "</tr>"
		}
		document.getElementById('tableContent').innerHTML = html;
		$(".station").click(function() {
			zoomTostation($(this).attr("station_id"));

		});
	}
}

//下一页
function next() {
	var countPage = Math.ceil(kzmbData.length / 5);
	if(currentIndex == countPage) {
		alert("这是第最后一页");

	} else {
		var html = "";
		var selectobject = document.getElementById("water");
		var selectobject1 = document.getElementById("temElement");
		var thValue = document.getElementById("changeName");
		if(selectobject.checked) {
			thValue.innerHTML = selectobject.value;
		} else {
			thValue.innerHTML = selectobject1.value;
		}
		currentIndex++;
		if(currentIndex < countPage) {
			for(var i = 0; i < 5; i++) {
				html += "<tr>";
				for(var j = 0; j < 3; j++) {
					//							html += "<td onclick='zoomTostation(""" + data.DS[i]["Station_Id_C"].toString() + """)'>";
					html += "<td class='station' station_id=" + kzmbData[(currentIndex - 1) * 5 + i]["Station_Id_C"].toString() + ">";

					if(j == 0) {
						html += kzmbData[(currentIndex - 1) * 5 + i]["Station_Id_C"].toString();
					} else if(j == 1) {
						html += kzmbData[(currentIndex - 1) * 5 + i]["Station_Name"].toString();
					} else if(j == 2) {
						if(selectobject.checked) {
							html += kzmbData[(currentIndex - 1) * 5 + i]["PRE_1h"].toString();
						} else {
							html += kzmbData[(currentIndex - 1) * 5 + i]["TEM"].toString();
						}

					}

					html += "</td>";
				}
				html += "</tr>"
			}
		} else {
			for(var i = 0; i < kzmbData.length - 5 * (currentIndex - 1); i++) {
				html += "<tr>";
				for(var j = 0; j < 3; j++) {
					//							html += "<td onclick='zoomTostation(""" + data.DS[i]["Station_Id_C"].toString() + """)'>";
					html += "<td class='station' station_id=" + kzmbData[(currentIndex - 1) * 5 + i]["Station_Id_C"].toString() + ">";

					if(j == 0) {
						html += kzmbData[(currentIndex - 1) * 5 + i]["Station_Id_C"].toString();
					} else if(j == 1) {
						html += kzmbData[(currentIndex - 1) * 5 + i]["Station_Name"].toString();
					} else if(j == 2) {
						if(selectobject.checked) {
							html += kzmbData[(currentIndex - 1) * 5 + i]["PRE_1h"].toString();
						} else {
							html += kzmbData[(currentIndex - 1) * 5 + i]["TEM"].toString();
						}

					}

					html += "</td>";
				}
				html += "</tr>"
			}
		}

		document.getElementById('tableContent').innerHTML = html;
		$(".station").click(function() {
			zoomTostation($(this).attr("station_id"));
		});
	}
}